function initPage(baseInfoJson,hospitalVisitJson){
	var basePath = $("#basePath").val();
	var medicalPayMentTypesData = baseInfoJson['medicalPayMentTypes'];//付费方式
	var marriages=baseInfoJson['marriages'];//婚姻
	var sexs=baseInfoJson['sexs'];//性别
	var idDocumentTypes=baseInfoJson['idDocumentTypes'];//证件类型
	var nationalitys=baseInfoJson['nationalitys'];//国籍
	var nations=baseInfoJson['nations'];//民族
	var relativeRelations=baseInfoJson['relativeRelations'];//与病人关系
	var inHospitalTypes=baseInfoJson['inHospitalTypes'];//入院途径
	var inHospitalStates=baseInfoJson['inHospitalStates'];//入院状况
	var outHospitalTypes=baseInfoJson['outHospitalTypes'];//离院方式
	var professions=baseInfoJson['professions'];//职业
	var medicalDepts=baseInfoJson['medicalDepts'];//科室
	
	var rehospitalAims=baseInfoJson['rehospitalAims'];//在住院目的
	
	var hospitalDealthReasons=baseInfoJson['hospitalDealthReasons'];//死亡原因

	$("select").each(function(){
		$(this).append("<option value=''>---请选择---</option>");
		
	});
	
	$("#medicalPayTypeCode").each(function(){
		var options = "";
		for(var index in medicalPayMentTypesData){
			var medicalPayMentType = medicalPayMentTypesData[index];
	    	options+="<option value='"+medicalPayMentType.uniq_code+"'>"+medicalPayMentType.label+"</option>"
	    } 
       $(this).append(options);
       $(this).change(function(){
	   		var eventObj = $(this);
	   		var nameObjName = eventObj.attr("name").replace("Code", "Name");
	   		
	   		if(eventObj.val()!=""){
	   			var name=eventObj.find("option:selected").text();
	   			eventObj.next("input[name='"+nameObjName+"']").val(name);
	   		}else{
	   			eventObj.next("input[name='"+nameObjName+"']").val("");
	   		}
	   	});
	});
	var medicalPayTypeOjb = $("#medicalPayTypeCode");
	if(hospitalVisitJson.medicalPayTypeCode){
		
		var selectOption = medicalPayTypeOjb.find("option[value='"+hospitalVisitJson.medicalPayTypeCode+"']")
		if(selectOption.length > 0){
			selectOption.attr("selected",true);
		}else{
			medicalPayTypeOjb.append("<option selected='selected' value='"+hospitalVisitJson.medicalPayTypeCode+"'>"+hospitalVisitJson.medicalPayTypeName+"</option>");
		}
		
	}
	var medicalPayTypeName = medicalPayTypeOjb.attr("name").replace("Code", "Name");
	medicalPayTypeOjb.next("input[name='"+medicalPayTypeName+"']").val(hospitalVisitJson.medicalPayTypeName);
	//婚姻下拉框
	$("#marriageCode").each(function(){
		var options = "";
		for(var index in marriages){
			var marriage = marriages[index];
	    	options+="<option value='"+marriage.uniq_code+"'>"+marriage.label+"</option>"
	    } 
       $(this).append(options);
       $(this).change(function(){
	   		var eventObj = $(this);
	   		var nameObjName = eventObj.attr("name").replace("Code", "Name");
	   		
	   		if(eventObj.val()!=""){
	   			var name=eventObj.find("option:selected").text();
	   			eventObj.next("input[name='"+nameObjName+"']").val(name);
	   		}else{
	   			eventObj.next("input[name='"+nameObjName+"']").val("");
	   		}
	   	});
	});
	
	var marriageCodeOjb = $("#marriageCode");
	if(hospitalVisitJson.marriageCode){
		
		var selectOption = marriageCodeOjb.find("option[value='"+hospitalVisitJson.marriageCode+"']")
		if(selectOption.length > 0){
			selectOption.attr("selected",true);
		}else{
			marriageCodeOjb.append("<option selected='selected' value='"+hospitalVisitJson.marriageCode+"'>"+hospitalVisitJson.marriageName+"</option>");
		}
		
	}
	marriageCodeOjb.next("input[name='"+marriageCodeOjb.attr("name").replace("Code", "Name")+"']").val(hospitalVisitJson.marriageName);
	
	
	$( ".medical_worker_search_input" ).autocomplete({
		source: function( request, response ) {
			var eventObj = $(this.element);
			
			var codeObjName = eventObj.attr("name").replace("Name", "Code");
			eventObj.next("input[name='"+codeObjName+"']").val("");
			/* eventObj.next("input[data-code='search_input1']").val(""); */
			$.ajax({
				url: basePath + "base_info/ajax_medical_worker_by_query_name",
				dataType: "json",
				data:{
					queryName: request.term
				},
				success: function( data ) {
				response( $.map( data, function( item ) {
					return {
						label:item.label,
						uniq_code:item.uniq_code
					}
				}));
			}
		});
		},
		minLength: 1,
		select: function( event, ui ) {
			var eventObj = $(this);
			var item = ui.item;
			var codeObjName = eventObj.attr("name").replace("Name", "Code");
			eventObj.next("input[name='"+codeObjName+"']").val(item.uniq_code);
			/* eventObj.next("input[data-code='search_input1']").val(item.code); */
		},search: function( event, ui ) {
			var eventObj = $(this);
			/* eventObj.next("input[data-code='search_input1']").val(""); */
			var codeObjName = eventObj.attr("name").replace("Name", "Code");
			eventObj.next("input[name='"+codeObjName+"']").val("");
		}
	});
	//性别下拉框
	$("#sexCode").each(function(){
		var options = "";
		for(var index in sexs){
			var sex = sexs[index];
	    	options+="<option value='"+sex.uniq_code+"'>"+sex.label+"</option>"
	    } 
       $(this).append(options);
       $(this).change(function(){
	   		var eventObj = $(this);
	   		var nameObjName = eventObj.attr("name").replace("Code", "Name");
	   		
	   		if(eventObj.val()!=""){
	   			var name=eventObj.find("option:selected").text();
	   			eventObj.next("input[name='"+nameObjName+"']").val(name);
	   		}else{
	   			eventObj.next("input[name='"+nameObjName+"']").val("");
	   		}
	   	});
	});
	
	var sexCodeOjb = $("#sexCode");
	if(hospitalVisitJson.sexCode){
		
		var selectOption = sexCodeOjb.find("option[value='"+hospitalVisitJson.sexCode+"']")
		if(selectOption.length > 0){
			selectOption.attr("selected",true);
		}else{
			sexCodeOjb.append("<option selected='selected' value='"+hospitalVisitJson.sexCode+"'>"+hospitalVisitJson.sexName+"</option>");
		}
		
	}
	sexCodeOjb.next("input[name='"+sexCodeOjb.attr("name").replace("Code", "Name")+"']").val(hospitalVisitJson.sexName);
	
	//证件类型
	$("#idDocumentTypeCode").each(function(){
		var options = "";
		for(var index in idDocumentTypes){
			var idDocumentType = idDocumentTypes[index];
	    	options+="<option value='"+idDocumentType.uniq_code+"'>"+idDocumentType.label+"</option>"
	    } 
       $(this).append(options);
       $(this).change(function(){
	   		var eventObj = $(this);
	   		var nameObjName = eventObj.attr("name").replace("Code", "Name");
	   		
	   		if(eventObj.val()!=""){
	   			var name=eventObj.find("option:selected").text();
	   			eventObj.next("input[name='"+nameObjName+"']").val(name);
	   		}else{
	   			eventObj.next("input[name='"+nameObjName+"']").val("");
	   		}
	   	});
	});

	
	var idDocumentTypeOjb = $("#idDocumentTypeCode");
	if(hospitalVisitJson.idDocumentTypeCode){
		
		var selectOption = idDocumentTypeOjb.find("option[value='"+hospitalVisitJson.idDocumentTypeCode+"']")
		if(selectOption.length > 0){
			selectOption.attr("selected",true);
		}else{
			idDocumentTypeOjb.append("<option selected='selected' value='"+hospitalVisitJson.idDocumentTypeCode+"'>"+hospitalVisitJson.idDocumentTypeName+"</option>");
		}
		
	}
	var idDocumentTypeName = idDocumentTypeOjb.attr("name").replace("Code", "Name");
	idDocumentTypeOjb.next("input[name='"+idDocumentTypeName+"']").val(hospitalVisitJson.idDocumentTypeName);
	//国籍
	$("#nationalityCode").each(function(){
		var options = "";
		for(var index in nationalitys){
			var nationality = nationalitys[index];
	    	options+="<option value='"+nationality.uniq_code+"'>"+nationality.label+"</option>"
	    } 
       $(this).append(options);
       $(this).change(function(){
	   		var eventObj = $(this);
	   		var nameObjName = eventObj.attr("name").replace("Code", "Name");
	   		
	   		if(eventObj.val()!=""){
	   			var name=eventObj.find("option:selected").text();
	   			eventObj.next("input[name='"+nameObjName+"']").val(name);
	   		}else{
	   			eventObj.next("input[name='"+nameObjName+"']").val("");
	   		}
	   	});
	});
	
	var nationalityCodeOjb = $("#nationalityCode");
	if(hospitalVisitJson.nationalityCode){
		
		var selectOption = nationalityCodeOjb.find("option[value='"+hospitalVisitJson.nationalityCode+"']")
		if(selectOption.length > 0){
			selectOption.attr("selected",true);
		}else{
			nationalityCodeOjb.append("<option selected='selected' value='"+hospitalVisitJson.nationalityCode+"'>"+hospitalVisitJson.nationalityName+"</option>");
		}
		
	}
	nationalityCodeOjb.next("input[name='"+nationalityCodeOjb.attr("name").replace("Code", "Name")+"']").val(hospitalVisitJson.nationalityName);
	
	
	//民族
	$("#nationCode").each(function(){
		var options = "";
		for(var index in nations){
			var nation = nations[index];
	    	options+="<option value='"+nation.uniq_code+"'>"+nation.label+"</option>"
	    } 
       $(this).append(options);
       $(this).change(function(){
	   		var eventObj = $(this);
	   		var nameObjName = eventObj.attr("name").replace("Code", "Name");
	   		
	   		if(eventObj.val()!=""){
	   			var name=eventObj.find("option:selected").text();
	   			eventObj.next("input[name='"+nameObjName+"']").val(name);
	   		}else{
	   			eventObj.next("input[name='"+nameObjName+"']").val("");
	   		}
	   	});
	});
	var nationCodeOjb = $("#nationCode");
	if(hospitalVisitJson.nationCode){
		
		var selectOption = nationCodeOjb.find("option[value='"+hospitalVisitJson.nationCode+"']")
		if(selectOption.length > 0){
			selectOption.attr("selected",true);
		}else{
			nationCodeOjb.append("<option selected='selected' value='"+hospitalVisitJson.nationCode+"'>"+hospitalVisitJson.nationName+"</option>");
		}
		
	}
	nationCodeOjb.next("input[name='"+nationCodeOjb.attr("name").replace("Code", "Name")+"']").val(hospitalVisitJson.nationName);
	
	var tjIdentifys=baseInfoJson['personalTypes'];//身份
	
	$("#personnelCategorySelect").each(function(){
		var options = "";
		for(var index in tjIdentifys){
			var tjIdentify = tjIdentifys[index];
	    	options+="<option value='"+tjIdentify.code+"'>"+tjIdentify.name+"</option>"
	    } 
       $(this).append(options);
       $(this).change(function(){
	   		var eventObj = $(this);
	   		var nameObjName = eventObj.attr("name").replace("Code", "Name");
	   		
	   		if(eventObj.val()!=""){
	   			var name=eventObj.find("option:selected").text();
	   			eventObj.next("input[name='"+nameObjName+"']").val(name);
	   		}else{
	   			eventObj.next("input[name='"+nameObjName+"']").val("");
	   		}
	   	});
	});
	var personnelCategoryCodeOjb = $("#personnelCategorySelect");
	if(hospitalVisitJson.personnelCategoryCode){
		
		var selectOption = personnelCategoryCodeOjb.find("option[value='"+hospitalVisitJson.personnelCategoryCode+"']")
		if(selectOption.length > 0){
			selectOption.attr("selected",true);
		}else{
			personnelCategoryCodeOjb.append("<option selected='selected' value='"+hospitalVisitJson.personnelCategoryCode+"'>"+hospitalVisitJson.personnelCategoryName+"</option>");
		}
		
	}
	personnelCategoryCodeOjb.next("input[name='"+personnelCategoryCodeOjb.attr("name").replace("Code", "Name")+"']").val(hospitalVisitJson.personnelCategoryName);
	
	
	var tjTopUnits=baseInfoJson['tjTopUnits'];//大单位
	
	$("#majorUnitSelect").each(function(){
		var options = "";
		for(var index in tjTopUnits){
			var tjTopUnit = tjTopUnits[index];
	    	options+="<option value='"+tjTopUnit.uniq_code+"'>"+tjTopUnit.label+"</option>"
	    } 
       $(this).append(options);
       $(this).change(function(){
	   		var eventObj = $(this);
	   		var nameObjName = eventObj.attr("name").replace("Code", "Name");
	   		
	   		if(eventObj.val()!=""){
	   			var name=eventObj.find("option:selected").text();
	   			eventObj.next("input[name='"+nameObjName+"']").val(name);
	   		}else{
	   			eventObj.next("input[name='"+nameObjName+"']").val("");
	   		}
	   	});
	});
	var majorUnitCodeOjb = $("#majorUnitSelect");
	if(hospitalVisitJson.majorUnitCode){
		
		var selectOption = majorUnitCodeOjb.find("option[value='"+hospitalVisitJson.majorUnitCode+"']")
		if(selectOption.length > 0){
			selectOption.attr("selected",true);
		}else{
			majorUnitCodeOjb.append("<option selected='selected' value='"+hospitalVisitJson.majorUnitCode+"'>"+hospitalVisitJson.majorUnitName+"</option>");
		}
		
	}
	majorUnitCodeOjb.next("input[name='"+majorUnitCodeOjb.attr("name").replace("Code", "Name")+"']").val(hospitalVisitJson.majorUnitName);
	
	var tjDutys=baseInfoJson['tjDutys'];//勤务
	
	$("#troopServiceSelect").each(function(){
		var options = "";
		for(var index in tjDutys){
			var tjDuty = tjDutys[index];
	    	options+="<option value='"+tjDuty.uniq_code+"'>"+tjDuty.label+"</option>"
	    } 
       $(this).append(options);
       $(this).change(function(){
	   		var eventObj = $(this);
	   		var nameObjName = eventObj.attr("name").replace("Code", "Name");
	   		
	   		if(eventObj.val()!=""){
	   			var name=eventObj.find("option:selected").text();
	   			eventObj.next("input[name='"+nameObjName+"']").val(name);
	   		}else{
	   			eventObj.next("input[name='"+nameObjName+"']").val("");
	   		}
	   	});
	});
	var troopServiceCodeOjb = $("#troopServiceSelect");
	if(hospitalVisitJson.troopServiceCode){
		
		var selectOption = troopServiceCodeOjb.find("option[value='"+hospitalVisitJson.troopServiceCode+"']")
		if(selectOption.length > 0){
			selectOption.attr("selected",true);
		}else{
			troopServiceCodeOjb.append("<option selected='selected' value='"+hospitalVisitJson.troopServiceCode+"'>"+hospitalVisitJson.troopServiceName+"</option>");
		}
		
	}
	troopServiceCodeOjb.next("input[name='"+troopServiceCodeOjb.attr("name").replace("Code", "Name")+"']").val(hospitalVisitJson.troopServiceName);
	
	
	//医疗体系
	$("#medicalSystemSelect").each(function(){
		var options = "<option value='0'>非体系病人</option>";
		options+="<option value='1'>体系病人</option>"
		options+="<option value='9'>其他</option>"
		
       $(this).append(options);
       $(this).change(function(){
	   		var eventObj = $(this);
	   		var nameObjName = eventObj.attr("name").replace("Code", "Name");
	   		
	   		if(eventObj.val()!=""){
	   			var name=eventObj.find("option:selected").text();
	   			eventObj.next("input[name='"+nameObjName+"']").val(name);
	   		}else{
	   			eventObj.next("input[name='"+nameObjName+"']").val("");
	   		}
	   	});
	});
	var medicalSystemCodeOjb = $("#medicalSystemSelect");
	if(hospitalVisitJson.medicalSystemCode){
		
		var selectOption = medicalSystemCodeOjb.find("option[value='"+hospitalVisitJson.medicalSystemCode+"']")
		if(selectOption.length > 0){
			selectOption.attr("selected",true);
		}else{
			medicalSystemCodeOjb.append("<option selected='selected' value='"+hospitalVisitJson.medicalSystemCode+"'>"+hospitalVisitJson.medicalSystemName+"</option>");
		}
		
	}
	medicalSystemCodeOjb.next("input[name='"+medicalSystemCodeOjb.attr("name").replace("Code", "Name")+"']").val(hospitalVisitJson.medicalSystemName);
	
	
	$("#idTypeSelect").each(function(){
		var options = "";
		for(var index in tjIdentifys){
			var tjIdentify = tjIdentifys[index];
	    	options+="<option value='"+tjIdentify.uniq_code+"'>"+tjIdentify.label+"</option>"
	    } 
       $(this).append(options);
       $(this).change(function(){
	   		var eventObj = $(this);
	   		var nameObjName = eventObj.attr("name").replace("Code", "Name");
	   		
	   		if(eventObj.val()!=""){
	   			var name=eventObj.find("option:selected").text();
	   			eventObj.next("input[name='"+nameObjName+"']").val(name);
	   		}else{
	   			eventObj.next("input[name='"+nameObjName+"']").val("");
	   		}
	   	});
	});
	var idTypeCodeOjb = $("#idTypeSelect");
	if(hospitalVisitJson.idTypeCode){
		
		var selectOption = idTypeCodeOjb.find("option[value='"+hospitalVisitJson.idTypeCode+"']")
		if(selectOption.length > 0){
			selectOption.attr("selected",true);
		}else{
			idTypeCodeOjb.append("<option selected='selected' value='"+hospitalVisitJson.idTypeCode+"'>"+hospitalVisitJson.idTypeName+"</option>");
		}
		
	}
	idTypeCodeOjb.next("input[name='"+idTypeCodeOjb.attr("name").replace("Code", "Name")+"']").val(hospitalVisitJson.idTypeName);
	
	
	var tjChargeTypes=baseInfoJson['tjChargeTypes'];//费别
	
	$("#costTypeSelect").each(function(){
		var options = "";
		for(var index in tjChargeTypes){
			var tjChargeType = tjChargeTypes[index];
	    	options+="<option value='"+tjChargeType.uniq_code+"'>"+tjChargeType.label+"</option>"
	    } 
       $(this).append(options);
       $(this).change(function(){
	   		var eventObj = $(this);
	   		var nameObjName = eventObj.attr("name").replace("Code", "Name");
	   		
	   		if(eventObj.val()!=""){
	   			var name=eventObj.find("option:selected").text();
	   			eventObj.next("input[name='"+nameObjName+"']").val(name);
	   		}else{
	   			eventObj.next("input[name='"+nameObjName+"']").val("");
	   		}
	   	});
	});
	var costTypeCodeOjb = $("#costTypeSelect");
	if(hospitalVisitJson.costTypeCode){
		
		var selectOption = costTypeCodeOjb.find("option[value='"+hospitalVisitJson.costTypeCode+"']")
		if(selectOption.length > 0){
			selectOption.attr("selected",true);
		}else{
			costTypeCodeOjb.append("<option selected='selected' value='"+hospitalVisitJson.costTypeCode+"'>"+hospitalVisitJson.costTypeName+"</option>");
		}
		
	}
	costTypeCodeOjb.next("input[name='"+costTypeCodeOjb.attr("name").replace("Code", "Name")+"']").val(hospitalVisitJson.costTypeName);
	
	
	//在职状况
	$("#jobStateSelect").each(function(){
		var options = "<option value='0'>在职</option>";
		options+="<option value='1'>离职</option>"
		options+="<option value='2'>退休</option>"
		options+="<option value='3'>无</option>"
		
       $(this).append(options);
       $(this).change(function(){
	   		var eventObj = $(this);
	   		var nameObjName = eventObj.attr("name").replace("Code", "Name");
	   		
	   		if(eventObj.val()!=""){
	   			var name=eventObj.find("option:selected").text();
	   			eventObj.next("input[name='"+nameObjName+"']").val(name);
	   		}else{
	   			eventObj.next("input[name='"+nameObjName+"']").val("");
	   		}
	   	});
	});
	var jobStateCodeOjb = $("#jobStateSelect");
	if(hospitalVisitJson.jobStateCode){
		
		var selectOption = jobStateCodeOjb.find("option[value='"+hospitalVisitJson.jobStateCode+"']")
		//alert(JSON.stringify(hospitalVisitJson.jobStateCode));
		if(selectOption.length > 0){
			selectOption.attr("selected",true);
		}else{
			jobStateCodeOjb.append("<option selected='selected' value='"+hospitalVisitJson.jobStateCode+"'>"+hospitalVisitJson.jobStateName+"</option>");
		}
		
	}
	jobStateCodeOjb.next("input[name='"+jobStateCodeOjb.attr("name").replace("Code", "Name")+"']").val(hospitalVisitJson.jobStateName);
	
	
	//军事训练伤
	$("#militaryTrainingInjurySelect").each(function(){
		var options = "<option value='1'>是</option>";
		options+="<option value='2'>否</option>";
		
       $(this).append(options);
       $(this).change(function(){
	   		var eventObj = $(this);
	   		var nameObjName = eventObj.attr("name").replace("Code", "Name");
	   		
	   		if(eventObj.val()!=""){
	   			var name=eventObj.find("option:selected").text();
	   			eventObj.next("input[name='"+nameObjName+"']").val(name);
	   		}else{
	   			eventObj.next("input[name='"+nameObjName+"']").val("");
	   		}
	   	});
	});
	var militaryTrainingInjuryCodeOjb = $("#militaryTrainingInjurySelect");
	if(hospitalVisitJson.militaryTrainingInjuryCode){
		
		var selectOption = militaryTrainingInjuryCodeOjb.find("option[value='"+hospitalVisitJson.militaryTrainingInjuryCode+"']")
		if(selectOption.length > 0){
			selectOption.attr("selected",true);
		}else{
			militaryTrainingInjuryCodeOjb.append("<option selected='selected' value='"+hospitalVisitJson.militaryTrainingInjuryCode+"'>"+hospitalVisitJson.militaryTrainingInjuryName+"</option>");
		}
		
	}
	militaryTrainingInjuryCodeOjb.next("input[name='"+militaryTrainingInjuryCodeOjb.attr("name").replace("Code", "Name")+"']").val(hospitalVisitJson.militaryTrainingInjuryName);
	
	
	//与病人关系
	$("#linkManRelativeRelationCode").each(function(){
		var options = "";
		for(var index in relativeRelations){
			var relativeRelation = relativeRelations[index];
	    	options+="<option value='"+relativeRelation.uniq_code+"'>"+relativeRelation.label+"</option>"
	    } 
       $(this).append(options);
       $(this).change(function(){
	   		var eventObj = $(this);
	   		var nameObjName = eventObj.attr("name").replace("Code", "Name");
	   		
	   		if(eventObj.val()!=""){
	   			var name=eventObj.find("option:selected").text();
	   			eventObj.next("input[name='"+nameObjName+"']").val(name);
	   		}else{
	   			eventObj.next("input[name='"+nameObjName+"']").val("");
	   		}
	   	});
	});
	
	var linkManRelativeRelationCodeOjb = $("#linkManRelativeRelationCode");
	if(hospitalVisitJson.linkManRelativeRelationCode){
		
		var selectOption = linkManRelativeRelationCodeOjb.find("option[value='"+hospitalVisitJson.linkManRelativeRelationCode+"']")
		if(selectOption.length > 0){
			selectOption.attr("selected",true);
		}else{
			linkManRelativeRelationCodeOjb.append("<option selected='selected' value='"+hospitalVisitJson.linkManRelativeRelationCode+"'>"+hospitalVisitJson.linkManRelativeRelationName+"</option>");
		}
		
	}
	linkManRelativeRelationCodeOjb.next("input[name='"+linkManRelativeRelationCodeOjb.attr("name").replace("Code", "Name")+"']").val(hospitalVisitJson.linkManRelativeRelationName);
	
	
	//入院途径
	$("#inHospitalTypeCode").each(function(){
		var options = "";
		for(var index in inHospitalTypes){
			var inHospitalType = inHospitalTypes[index];
	    	options+="<option value='"+inHospitalType.uniq_code+"'>"+inHospitalType.label+"</option>"
	    } 
       $(this).append(options);
       $(this).change(function(){
	   		var eventObj = $(this);
	   		var nameObjName = eventObj.attr("name").replace("Code", "Name");
	   		
	   		if(eventObj.val()!=""){
	   			var name=eventObj.find("option:selected").text();
	   			eventObj.next("input[name='"+nameObjName+"']").val(name);
	   		}else{
	   			eventObj.next("input[name='"+nameObjName+"']").val("");
	   		}
	   	});
	});
	
	var inHospitalTypeCodeOjb = $("#inHospitalTypeCode");
	if(hospitalVisitJson.inHospitalTypeCode){
		
		var selectOption = inHospitalTypeCodeOjb.find("option[value='"+hospitalVisitJson.inHospitalTypeCode+"']")
		if(selectOption.length > 0){
			selectOption.attr("selected",true);
		}else{
			inHospitalTypeCodeOjb.append("<option selected='selected' value='"+hospitalVisitJson.inHospitalTypeCode+"'>"+hospitalVisitJson.inHospitalTypeName+"</option>");
		}
		
	}
	inHospitalTypeCodeOjb.next("input[name='"+inHospitalTypeCodeOjb.attr("name").replace("Code", "Name")+"']").val(hospitalVisitJson.inHospitalTypeName);
	
	
	//入院状况
	$("#inHospitalStateCode").each(function(){
		var options = "";
		for(var index in inHospitalStates){
			var inHospitalState = inHospitalStates[index];
	    	options+="<option value='"+inHospitalState.uniq_code+"'>"+inHospitalState.label+"</option>"
	    } 
       $(this).append(options);
       $(this).change(function(){
	   		var eventObj = $(this);
	   		var nameObjName = eventObj.attr("name").replace("Code", "Name");
	   		
	   		if(eventObj.val()!=""){
	   			var name=eventObj.find("option:selected").text();
	   			eventObj.next("input[name='"+nameObjName+"']").val(name);
	   		}else{
	   			eventObj.next("input[name='"+nameObjName+"']").val("");
	   		}
	   	});
	});
	
	var inHospitalStateCodeOjb = $("#inHospitalStateCode");
	if(hospitalVisitJson.inHospitalTypeCode){
		
		var selectOption = inHospitalStateCodeOjb.find("option[value='"+hospitalVisitJson.inHospitalStateCode+"']")
		if(selectOption.length > 0){
			selectOption.attr("selected",true);
		}else{
			inHospitalStateCodeOjb.append("<option selected='selected' value='"+hospitalVisitJson.inHospitalStateCode+"'>"+hospitalVisitJson.inHospitalStateName+"</option>");
		}
		
	}
	inHospitalStateCodeOjb.next("input[name='"+inHospitalStateCodeOjb.attr("name").replace("Code", "Name")+"']").val(hospitalVisitJson.inHospitalStateName);
	
	
	
	//离院方式
	$("#outHospitalTypeCode").each(function(){
		var options = "";
		for(var index in outHospitalTypes){
			var outHospitalType = outHospitalTypes[index];
	    	options+="<option value='"+outHospitalType.uniq_code+"'>"+outHospitalType.label+"</option>"
	    } 
       $(this).append(options);
       $(this).change(function(){
	   		var eventObj = $(this);
	   		var nameObjName = eventObj.attr("name").replace("Code", "Name");
	   		
	   		if(eventObj.val()!=""){
	   			var name=eventObj.find("option:selected").text();
	   			eventObj.next("input[name='"+nameObjName+"']").val(name);
	   		}else{
	   			eventObj.next("input[name='"+nameObjName+"']").val("");
	   		}
	   	});
	});
	
	var outHospitalTypeCodeOjb = $("#outHospitalTypeCode");
	if(hospitalVisitJson.outHospitalTypeCode){
		
		var selectOption = outHospitalTypeCodeOjb.find("option[value='"+hospitalVisitJson.outHospitalTypeCode+"']")
		if(selectOption.length > 0){
			selectOption.attr("selected",true);
		}else{
			outHospitalTypeCodeOjb.append("<option selected='selected' value='"+hospitalVisitJson.outHospitalTypeCode+"'>"+hospitalVisitJson.outHospitalTypeName+"</option>");
		}
		
	}
	outHospitalTypeCodeOjb.next("input[name='"+outHospitalTypeCodeOjb.attr("name").replace("Code", "Name")+"']").val(hospitalVisitJson.outHospitalTypeName);
	
	
	//职业
	$("#professionCode").each(function(){
		var options = "";
		for(var index in professions){
			var profession = professions[index];
	    	options+="<option value='"+profession.uniq_code+"'>"+profession.label+"</option>"
	    } 
       $(this).append(options);
       $(this).change(function(){
	   		var eventObj = $(this);
	   		var nameObjName = eventObj.attr("name").replace("Code", "Name");
	   		
	   		if(eventObj.val()!=""){
	   			var name=eventObj.find("option:selected").text();
	   			eventObj.next("input[name='"+nameObjName+"']").val(name);
	   		}else{
	   			eventObj.next("input[name='"+nameObjName+"']").val("");
	   		}
	   	});
	});
	
	var professionCodeOjb = $("#professionCode");
	if(hospitalVisitJson.professionCode){
		
		var selectOption = professionCodeOjb.find("option[value='"+hospitalVisitJson.professionCode+"']")
		if(selectOption.length > 0){
			selectOption.attr("selected",true);
		}else{
			professionCodeOjb.append("<option selected='selected' value='"+hospitalVisitJson.professionCode+"'>"+hospitalVisitJson.professionName+"</option>");
		}
		
	}
	professionCodeOjb.next("input[name='"+professionCodeOjb.attr("name").replace("Code", "Name")+"']").val(hospitalVisitJson.professionName);
	
	
	//入院科室
	$("#inDeptCode").each(function(){
		var options = "";
		for(var index in medicalDepts){
			var medicalDept = medicalDepts[index];
	    	options+="<option value='"+medicalDept.uniq_code+"'>"+medicalDept.label+"</option>"
	    } 
       $(this).append(options);
       $(this).change(function(){
	   		var eventObj = $(this);
	   		var nameObjName = eventObj.attr("name").replace("Code", "Name");
	   		
	   		if(eventObj.val()!=""){
	   			var name=eventObj.find("option:selected").text();
	   			eventObj.next("input[name='"+nameObjName+"']").val(name);
	   		}else{
	   			eventObj.next("input[name='"+nameObjName+"']").val("");
	   		}
	   	});
	});
	
	var inDeptCodeOjb = $("#inDeptCode");
	if(hospitalVisitJson.inDeptCode){
		
		var selectOption = inDeptCodeOjb.find("option[value='"+hospitalVisitJson.inDeptCode+"']")
		if(selectOption.length > 0){
			selectOption.attr("selected",true);
		}else{
			inDeptCodeOjb.append("<option selected='selected' value='"+hospitalVisitJson.inDeptCode+"'>"+hospitalVisitJson.inDeptName+"</option>");
		}
		
	}
	inDeptCodeOjb.next("input[name='"+inDeptCodeOjb.attr("name").replace("Code", "Name")+"']").val(hospitalVisitJson.inDeptName);
	
	//出院科室
	$("#outDeptCode").each(function(){
		var options = "";
		for(var index in medicalDepts){
			var medicalDept = medicalDepts[index];
	    	options+="<option value='"+medicalDept.uniq_code+"'>"+medicalDept.label+"</option>"
	    } 
       $(this).append(options);
       $(this).change(function(){
	   		var eventObj = $(this);
	   		var nameObjName = eventObj.attr("name").replace("Code", "Name");
	   		
	   		if(eventObj.val()!=""){
	   			var name=eventObj.find("option:selected").text();
	   			eventObj.next("input[name='"+nameObjName+"']").val(name);
	   		}else{
	   			eventObj.next("input[name='"+nameObjName+"']").val("");
	   		}
	   	});
	});
	var outDeptCodeOjb = $("#outDeptCode");
	if(hospitalVisitJson.outDeptCode){
		
		var selectOption = outDeptCodeOjb.find("option[value='"+hospitalVisitJson.outDeptCode+"']")
		if(selectOption.length > 0){
			selectOption.attr("selected",true);
		}else{
			outDeptCodeOjb.append("<option selected='selected' value='"+hospitalVisitJson.outDeptCode+"'>"+hospitalVisitJson.outDeptName+"</option>");
		}
		
	}
	outDeptCodeOjb.next("input[name='"+outDeptCodeOjb.attr("name").replace("Code", "Name")+"']").val(hospitalVisitJson.outDeptName);
	
	
	$("#rehospitalAimCode").each(function(){
		var options = "";
		for(var index in rehospitalAims){
			var rehospitalAim = rehospitalAims[index];
	    	options+="<option value='"+rehospitalAim.uniq_code+"'>"+rehospitalAim.label+"</option>"
	    } 
       $(this).append(options);
       $(this).change(function(){
	   		var eventObj = $(this);
	   		var nameObjName = eventObj.attr("name").replace("Code", "Name");
	   		
	   		if(eventObj.val()!=""){
	   			var name=eventObj.find("option:selected").text();
	   			eventObj.next("input[name='"+nameObjName+"']").val(name);
	   		}else{
	   			eventObj.next("input[name='"+nameObjName+"']").val("");
	   		}
	   	});
       
       if(hospitalVisitJson.rehospitalAimCode){
   		
	   		var selectOption = $(this).find("option[value='"+hospitalVisitJson.rehospitalAimCode+"']")
	   		if(selectOption.length > 0){
	   			selectOption.attr("selected",true);
	   		}else{
	   			$(this).append("<option selected='selected' value='"+hospitalVisitJson.rehospitalAimCode+"'>"+hospitalVisitJson.rehospitalAimName+"</option>");
	   		}
	   		
	   	}
       $(this).next("input[name='"+$(this).attr("name").replace("Code", "Name")+"']").val(hospitalVisitJson.rehospitalAimName);
	   	
	});
	
	
	
	
	$("#dealthReasonCode").each(function(){
		var options = "";
		for(var index in hospitalDealthReasons){
			var hospitalDealthReason = hospitalDealthReasons[index];
	    	options+="<option value='"+hospitalDealthReason.uniq_code+"'>"+hospitalDealthReason.label+"</option>"
	    } 
       $(this).append(options);
       $(this).change(function(){
	   		var eventObj = $(this);
	   		var nameObjName = eventObj.attr("name").replace("Code", "Name");
	   		
	   		if(eventObj.val()!=""){
	   			var name=eventObj.find("option:selected").text();
	   			eventObj.next("input[name='"+nameObjName+"']").val(name);
	   		}else{
	   			eventObj.next("input[name='"+nameObjName+"']").val("");
	   		}
	   	});
       if(hospitalVisitJson.dealthReasonCode){
      		
	   		var selectOption = $(this).find("option[value='"+hospitalVisitJson.dealthReasonCode+"']")
	   		if(selectOption.length > 0){
	   			selectOption.attr("selected",true);
	   		}else{
	   			$(this).append("<option selected='selected' value='"+hospitalVisitJson.dealthReasonCode+"'>"+hospitalVisitJson.dealthReasonName+"</option>");
	   		}
	   		
	   	}
      $(this).next("input[name='"+$(this).attr("name").replace("Code", "Name")+"']").val(hospitalVisitJson.dealthReasonName);
	   
	});
	
	$("input[name='autopsyCode']").each(function(){
		 $(this).click(function(){
			 var autopsyNameValue = "";
			 if($(this).val()=="1"){
				 autopsyNameValue = "是";
			 }else if($(this).val()=="0"){
				 autopsyNameValue = "否";
			 }
			 $(this).nextAll("input[name='"+$(this).attr("name").replace("Code", "Name")+"']").val(autopsyNameValue);
		 });
	});
	
	if(hospitalVisitJson.autopsyCode){
		$("input[name='autopsyCode'][value='"+hospitalVisitJson.autopsyCode+"']").attr("checked",true);
	}
	$("input[name='autopsyName']").val(hospitalVisitJson.autopsyName);
}


/**
 * 校验数据正确性
 * @returns
 */
function validateData(){
	
	//1.判断年龄不能为空
	var age =$("#age").val();
	if(!age){
		$("#age").css({"border":"1px solid red"});
		$("#age").attr("data-content","年龄不能为空!");
		$("#age").popover({placement:'left'});
		redIframe();
	
	}
	
	
	
	
	//2.判断付费类型
	var medicalPayTypeCode=$("#medicalPayTypeCode").val();
	if(!medicalPayTypeCode){
		$("#medicalPayTypeCode").css({"border-color":"red"});
		redIframe();
	}
	//付费方式为军队医改军事训练伤为空
	if(medicalPayTypeCode!='' && medicalPayTypeCode=='Z'){
		var militaryTrainingInjurySelect=$("#militaryTrainingInjurySelect").val();
		if(!militaryTrainingInjurySelect){
			$("#medicalPayTypeCode").css({"border-color":"red"});
			$("#militaryTrainingInjurySelect").css({"border-color":"red"});
			$("#medicalPayTypeCode").attr("data-content","出院方式为军政医改!须选择是否为军事训练伤!");
			$("#medicalPayTypeCode").popover({placement:'right'});
			$("#militaryTrainingInjurySelect").attr("data-content","出院方式为军政医改!须选择是否为军事训练伤!");
			$("#militaryTrainingInjurySelect").popover({placement:'right'});
			redIframe();
		}
		
	}
	
	
	//3.判断入院时间
	var inHospitalTime = $("input[name='inHospitalDateTime']").val();
	if(!inHospitalTime){
		 $("input[name='inHospitalDateTime']").css({"border":"1px solid red"});
		 
		 $("input[name='inHospitalDateTime']").attr("data-content","入院时间不能为空!!");
		 $("input[name='inHospitalDateTime']").popover({placement:'right'});
		 redIframe();
	}
	
	//4.判断出院院时间
	var outHospitalDateTime = $("input[name='outHospitalDateTime']").val();
	if(!outHospitalDateTime){
		 $("input[name='outHospitalDateTime']").css({"border":"1px solid red"});
		 $("input[name='outHospitalDateTime']").attr("data-content","出院时间不能为空!!");
		 $("input[name='outHospitalDateTime']").popover({placement:'right'});
		 redIframe();
	}
	
	//5.判断入院时间是否大于出院时间
	if(inHospitalTime!='' && outHospitalDateTime!=''){
		if(!comparateDate(outHospitalDateTime,inHospitalTime)){
			$("input[name='inHospitalDateTime']").css({"border":"1px solid red"});
			 $("input[name='outHospitalDateTime']").css({"border":"1px solid red"});
			 $("input[name='outHospitalDateTime']").attr("data-content","出院时间小于入院时间!");
			 $("input[name='outHospitalDateTime']").popover({placement:'right'});
			 $("input[name='inHospitalDateTime']").attr("data-content","出院时间小于入院时间!");
			 $("input[name='inHospitalDateTime']").popover({placement:'right'});
			 redIframe();
			
		}
	}
	
	//6.诊断时间
	var diagConfirmedDateTime = $("input[name='diagConfirmedDateTime']").val();
	if(!diagConfirmedDateTime){
		 $("input[name='diagConfirmedDateTime']").css({"border":"1px solid red"});
		 $("input[name='diagConfirmedDateTime']").attr("data-content","诊断时间不可为空!");
		 $("input[name='diagConfirmedDateTime']").popover({placement:'bottom'});
		 redIframe();
	}
	
	//7.如果诊断时间小于入院时间
	if(diagConfirmedDateTime!='' && inHospitalTime!=''){
		if(!comparateDate(diagConfirmedDateTime,inHospitalTime)){
			$("input[name='inHospitalDateTime']").css({"border":"1px solid red"});
			$("input[name='diagConfirmedDateTime']").css({"border":"1px solid red"});
			 $("input[name='diagConfirmedDateTime']").attr("data-content","诊断时间不能小于入院时间!");
			 $("input[name='diagConfirmedDateTime']").popover({placement:'bottom'});
			 $("input[name='inHospitalDateTime']").attr("data-content","诊断时间不能小于入院时间!");
			 $("input[name='inHospitalDateTime']").popover({placement:'right'});
			 redIframe();
		}
	}
	
	//8.如果诊断时间大于出院时间
	if(diagConfirmedDateTime!='' && outHospitalDateTime!=''){
		if(!comparateDate(outHospitalDateTime,diagConfirmedDateTime)){
			$("input[name='outHospitalDateTime']").css({"border":"1px solid red"});
			$("input[name='diagConfirmedDateTime']").css({"border":"1px solid red"});
			 $("input[name='diagConfirmedDateTime']").attr("data-content","诊断时间不能大于出院时间!");
			 $("input[name='diagConfirmedDateTime']").popover({placement:'bottom'});
			 $("input[name='outHospitalDateTime']").attr("data-content","诊断时间不能大于出院时间!");
			 $("input[name='outHospitalDateTime']").popover({placement:'right'});
			 redIframe();
		}
	}
	
	//离院方式为空
	var outHospitalTypeCode = $("#outHospitalTypeCode").val();
	if(!outHospitalTypeCode){
		$("#outHospitalTypeCode").css({"border-color":"red"});
		$("#outHospitalTypeCode").attr("data-content","离院方式不能为空!");
		$("#outHospitalTypeCode").popover({placement:'right'});
		redIframe();
	}
	//是否尸检
	var autopsyCode = $("input[name='autopsyCode']:checked").val();
	
	if(autopsyCode && outHospitalTypeCode!=3){
		$("#outHospitalTypeCode").css({"border-color":"red"});
		$("input[name='autopsyCode']:checked").css({"border":"1px solid red"});
		$("#outHospitalTypeCode").attr("data-content","尸检选择有或无!出院方式必须为死亡!");
		$("#outHospitalTypeCode").popover({placement:'right'});
		redIframe();
		
	}
	
	
	
}


function comparateDate(date1,data2){
	 var d1 = new Date(date1.replace(/\-/g, "\/"));  
	 var d2 = new Date(data2.replace(/\-/g, "\/"));  
	if(d1>=d2){
		return true;
	}
	return false;
}


function redIframe(iframeClass){
	parent.$(".tc_basic a").css({"color":"red"});

}